<form class="layui-form seller-form" action="">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li><a href="{:url('userSort')}">钱包日志查询</a></li>
            <li class="layui-this"><a href="{:url('userTran')}">消费日志(银12)</a></li>
            <li><a href="{:url('userTranDiff')}">消费日志(银3)</a></li>
            <li><a href="{:url('userUpdate')}">Flag(N=>X)</a></li>
            <li><a href="{:url('xfCardAmount')}">重查卡余额</a></li>
            <li><a href="{:url('addCashError')}">用户余额错误手动添加</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-form-item">
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="user_name" id="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="card_num" lay-verify="title" placeholder="Card Num" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="card_type" lay-verify="title" placeholder="卡头" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;width: 150px;">
                    <select name="tran_status" >
                        <option value="">Select Status</option>
                        {foreach $tran_type as $v_d}
                        <option value="{$v_d}">{$v_d}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline" style="padding-left: 5px;width: 150px;">
                    <select name="reversal_flag" >
                        <option value="">Reversal Flag</option>
                        <option value="X">X</option>
                        <option value="Y">Y</option>
                        <option value="N">N</option>
                    </select>
                </div>
                <div class="layui-inline" style="padding-left: 5px;width: 200px;">
                    <select name="Credit_556766" >
                        <option value="">请选择是否排除556766</option>
                        <option value="0">556766的Credit</option>
                        <option value="1">排除556766的Credit</option>
                    </select>
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="card_token" lay-verify="title" placeholder="请输入完整 cardToken" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="amount" lay-verify="title" placeholder="Input amount" autocomplete="off"
                           class="layui-input" style="width: 200px;">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="appCode" lay-verify="title" placeholder="请输入appCode" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="shopping" lay-verify="title" placeholder="请输入商家" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="desc" lay-verify="title" placeholder="请输入备注" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="datetime" id="datetime" placeholder="Start Time _ End Time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline seller-inline-3" style="width: 180px;">
                        <select name="bank_type" lay-verify="" >
                            <option value="">银行类型</option>
                            <option value="1">Comdata</option>
                            <option value="3">Connexpay</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user_data_update">Update Data</button>
                    </div>
                </div>
            </div>
            <div class="table-body">
                <table id="balanceTable" lay-filter="balanceTable"></table>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'laydate', 'table', 'element'], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        // laydate.render({
        //     elem: '#update_datetime',
        //     range: '_',
        //     format: 'yyyy-MM-dd'
        // });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('userTran')}",
            id: 'balanceTable',
            //where:{tran_token : $('#tran_token').val()},
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { type: 'numbers'},
                { field: 'username',  align: 'left', title: '会员',width: 180},
                { field: 'app_code',  align: 'left', title: 'AppCode',width: 90},
                { field: 'card_num', title: 'CardNum',width: 180,align:"left",totalRowText:'Total：', templet: function (d) {
                        const card_num = d.card_num;
                        const bank_type= d.bank_type;
                        var html = '<a class="layui-btn layui-btn-xs">' + bank_type + '</a>' +
                            '&nbsp;&nbsp;<a style="color: #0e8df3;" ' +
                            'href="' + "{:url('cards/cardLog')}?card_num=" + card_num + '">' + card_num + '</a>';
                        return html;
                    }
                },
                { field: 'type',  align: 'left', title: '交易状态',width: 110,
                    templet:function (d) {
                        const type = d.tran_status;
                        const flag = d.reversal_flag;
                        var color = '';
                        if(type == 'Declined'){
                            color = 'red';
                        }else if(type == 'Posted'){
                            color = 'green';
                        }else if(type == 'Authorized'){
                            if(flag == 'X' || flag == 'Y'){
                                color = '#00aeef';
                            }else{
                                color = 'gray';
                            }
                        }else if(type == 'Credit'){
                            color = '#00aeef';
                        }else if(type == 'Reversal'){
                            color = '#d39e00';
                        }
                        return "<span style='color:" + color + ";font-weight:bold'>" + type + "</span>"
                    },
                    totalRowText:'Total:'},
                { field: 'reversal_flag',  align: 'left', title: 'Flag',width: 60},
                { field: 'shopping',  align: 'left', title: '商家'},
                { field: 'desc',  align: 'left', title: '拒付原因',
                    templet:function (d) {
                        const desc = d.desc;
                        var   error_msg = desc;
                        if(desc == 'EXPIRATION DATE ERROR' || desc == 'VERIFY EXPIRATION DATE OR USE NEW CARD'){
                            error_msg= '卡片过期时间错误，请输入正确的过期时间';
                        }else if(desc == 'ORIGINAL TRANSACTION NOT FOUND' || desc == 'CALL CUSTOMER SERVICE'){
                            error_msg= 'ORIGINAL TRANSACTION NOT FOUND';
                        }else if(desc == 'ENHANCED RISK MONITORING DECLINE'){
                            error_msg= '高风险，已拒绝';
                        }else if(desc == 'TRANSACTION AMOUNT LIMIT EXCEEDED'
                            || desc == 'VERIFY AMOUNT AND ADJUST LIMIT'
                            || desc == 'No sufficient funds'
                        ){
                            error_msg= '卡片可用余额不足，请先充值';
                        }else if(desc == 'VERIFY CVC2 NUMBER ON BACK OF CARD'){
                            error_msg= '请输入正确的 CVV';
                        }else if(desc == 'CALL CUSTOMER SERVICE' || desc == 'CALL THE NUMBER ON THE BACK OF THE CARD'){
                            error_msg= '未知错误，请联系客服';
                        }else if(desc == 'CARD IS NOT ACTIVE' || desc == 'VERIFY CARD STATUS AND ACTIVATE CARD'){
                            error_msg= '卡片未激活，请先激活卡片';
                        }else if(desc == "INT\'L PURCHASES NOT ALLOWED" || desc == 'FLAG INTERNATIONAL ON CUST F6/05'){
                            error_msg= '该卡不能在美国地区以外消费';
                        }else if(desc == "CALL CREDIT DEPARTMENT"){
                            error_msg= '银行例行维护';
                        }else if(desc == "ENABLE ALERTS & NOTIFICATIONS"){
                            error_msg= '交易高风险被银行拒绝';
                        }else{
                            error_msg= desc;
                        }
                        return error_msg;
                        // return '<span id="' + d.id + '" style="color: green" ' +
                        //     'onmouseover="shows(\'' + error_msg + '\')" ' +
                        //     'onmouseleave="close_tips()">' + desc +'</span>';
                    }
                },
                { field: 'amount_auth',  align: 'right', title: '预扣款($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'ctime', align: 'center', title: '交易时间',width: 170},
                { field: 'amount_post',  align: 'right', title: '实际扣款($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true,
                    templet:function (d) {
                        var tran_status 	= d.tran_status;
                        const flag 			= d.reversal_flag;
                        var show_amount 	= d.amount_post;
                        var color           = '#FF5722';
                        if(tran_status == 'Authorized' && flag == 'N'){
                            color       = '#6c757d';
                            show_amount = d.amount_auth;
                        }
                        return "<span style='color: " + color + ";font-weight:bold'>" + show_amount + "</span>"
                    }
                },
                { field: 'utime', align: 'center', title: '结算时间',width: 170},
                { field: 'ctime_real', align: 'center', title: '银3交易时间',width: 170},
                { field: 'idMatchNumber', align: 'center', title: 'idMatchNumber',width: 200},
                { field: 'tran_token', align: 'center', title: 'tran_token',width: 200},
                { field: 'currencyCode', align: 'center', title: '币种',width: 200},
                { field: 'country', align: 'center', title: '交易发生地',width: 200},
                { field: 'id',  align: 'left', title: 'id',width: 200},
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100 ,500 ,1000],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        layui.form.on('submit(user_data_update)', function () {
            var loading =layer.load(1, {shade: [0.1,'#fff']});
            JsPost("{:url('updateUserTran')}",{username:$("#user_name").val()}, function(res){
                layer.close(loading);
                if(res.code >0){
                    $('#up_time').text(res.data.time);
                    layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                        tableIn.reload({
                            page:{
                                curr :1
                            }
                        });
                    });
                }else{
                    layer.msg(res.msg , {time:1500 , icon:2});
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });



    function shows(msg , id){
        layer.tips('' + msg, '#' + id ,{tips:[1,'blace'] , area:[100,40]});
    }
    function close_tips(){
        layer.closeAll();
    }
</script>